using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
public partial class Admin_KhachHangEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    private void load_data()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbKhachHang  khachhang = tbKhachHangBUS .GetByID (id);
            if (khachhang  != null)
            {
                txt_MaKH.Text = khachhang.IdKhachHang.ToString();
                txt_TenKH.Text = khachhang.HoTen.ToString();
                txt_Email.Text = khachhang.Email .ToString();
                txt_MatKhau.Text = khachhang.MatKhau.ToString();
                txt_diachi.Text = khachhang.DiaChi.ToString();
                txt_dienthoai.Text = khachhang.DienThoai .ToString();
            }
        }
        catch
        {
            Response.Redirect("~/Admin/KhachHangList.aspx");
        }
    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        try
        {
            tbKhachHang  khachhang = tbKhachHangBUS .GetByID (int.Parse(txt_MaKH .Text));
            khachhang.IdKhachHang = int.Parse (txt_MaKH.Text);
            khachhang.HoTen = txt_TenKH.Text;
            khachhang.Email = txt_Email.Text;
            khachhang.MatKhau = txt_MatKhau.Text;
            khachhang.DiaChi = txt_diachi.Text;
            khachhang.DienThoai = txt_dienthoai.Text;
            tbKhachHangBUS .Update (khachhang );
            Response.Redirect("~/Admin/KhachHangList.aspx");
        }
        catch
        {
            Response.Redirect("~/Admin/KhachHangList.aspx");
        }
    }
}
